<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div class="header_divStyle">
        <!-- <img class="imgStyle" src="../assets/03a290abfe5e6884640c68669b7d1c3a.jpg" alt=""> -->
        <!-- <img class="imgStyle" src="../assets/logo.png" alt=""> -->
        <img class="imgStyle" src="../assets/logo.png" alt="">
        <!-- <span>后台管理系统</span> -->
      </div>
      <div>
        <span>{{this.Info}}</span>
      <span class="huanying">欢迎您</span>
      <span @click="personPage">个人中心</span>
      <el-button type="warning" @click="logout">退出</el-button>
      </div>
      <!-- <el-button type="warning" plain @click="logout">退出</el-button> -->
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCoallapse ? '64px' : '200px'">
        <div  class="toggle-button" 
        @click="toggleCollapse"
        >|||</div>
        <!-- unique-opened true 只展开一个菜单 -->
        <el-menu  :default-active="activePath" router :collapse-transition="false" :collapse="isCoallapse"
          :unique-opened="false" class="el-menu-vertical-demo" background-color="#373d41" text-color="#fff"
          active-text-color="#409eff">
          <!-- 一级菜单 -->
          <el-submenu :index="item.menuId + ''" v-for="item in treeData" :key="item.menuId">
            <!-- 一级菜单模板区域 -->
            <template slot="title">
              <i :class="iconsObj[item.id]"></i>
              <span>{{ item.menuName }}</span>
            </template>
            <!-- 二级菜单 -->
            <div v-for="subItem in item.children" :key="subItem.menuId">
              <!-- 短信管理的三级菜单 -->
              <el-menu-item :index="'' + subItem.url + ''" @click="saveNavState('' + subItem.url + '')" v-if="subItem.menuName!=='短信管理'">
              <template slot="title">
                <!-- 图标 -->
                <i class="el-icon-menu"></i>
                <span>{{ subItem.menuName }}</span>
              </template>
            </el-menu-item>
              <!-- 没有三级菜单的用el-submenu  -->
            <el-submenu :index="'' + subItem.url + ''" v-else>
                <template slot="title">
                  <!-- 图标 -->
                  <i class="el-icon-menu"></i>
                  <span>{{ subItem.menuName }}</span>
                </template>
                  <el-menu-item :index="'' + v.url + ''" v-for="(v,index) in subItem.children" :key="index" @click="saveNavState('' + v.url + '')">
                    <!-- 图标 -->
                  <i class="el-icon-menu"></i>
                  <span>{{ v.menuName }}</span>
                  </el-menu-item>
              </el-submenu>
            </div>
            
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主题内容 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
        <span class="titleStyle">版权所有：河南祺智科技有限公司 © {{ time }} - {{ timeAddOne }}</span>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      Info: '',
      time: '',
      timeAddOne:'',
      // 左侧菜单数据(接口)
      treeData:[],
      // 左侧菜单数据
      menulist: [
        {
          id: 125, authName: "用户管理", path: "users",
          children: [
            { id: 1, authName: "用户列表", path: "users", },
            { id: 2, authName: "部门管理", path: "department" },
            { id: 3, authName: "角色管理", path: "roles" },
            { id: 4, authName: "菜单管理", path: "menu" },
            { id: 5, authName: "字典管理", path: "dict" },
            { id: 6, authName: "路由管理", path: "test" },
            { id: 6, authName: "系统变量菜单", path: "system" },
          ]
        }, {
          id: 103, authName: "系统监控", path: "rights",
          children: [
            { id: 5, authName: "在线用户", path: "online" },
            { id: 6, authName: "定时任务", path: "tasks" },
            { id: 7, authName: "正常日志", path: "operationLog" },
            { id: 8, authName: "服务监控", path: "service" },
          ]
        },
      ],
      iconsObj: {
        '125': 'iconfont icon-kehu-03-03',
        '103': 'iconfont icon-huiyuanqiaguanli',
        '101': 'iconfont icon-kehu-03-03',
        '102': 'iconfont icon-wodebaobiao',
        '145': 'iconfont icon--shenhedengji',
        // children: {
        //   '1': 'iconfont icon-kehu-03-03',
        // }
      },
      //   是否折叠
      isCoallapse: false,
      activePath: '',
    }
  },
  created() {
    this.getMenuList()
    this.activePath = sessionStorage.getItem("activePath")
  },
  methods: {
    logout() {
      sessionStorage.clear();
      this.$router.push('/login')
    },
    // 获取所有的菜单
    async getMenuList() {
      var date = new Date();
      this.time = date.getFullYear();//表示当前日期
      this.timeAddOne = date.getFullYear() + 1;//表示当前日期
      this.Info = sessionStorage.getItem('userInfo')
      this.treeData = JSON.parse(sessionStorage.getItem('treeData'))
      console.log(this.treeData);
      // const { data: res } = await this.$http.get('menus')
      // if (res.code === !10001) return this.$message.error(res.msg)
      // // 获取成功之后赋值给左侧菜单
      // console.log(this.menulist, '1');
    },
    // 左侧菜单栏 切换展开与折叠
    toggleCollapse() {
      this.isCoallapse = !this.isCoallapse
    },
    // 保存链接的激活状态
    saveNavState(activePath) {
      sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
      console.log(activePath);
    },
    personPage() {
      console.log(1);
      this.$router.push('/personInfo')
    },
  }
}
</script>

<style scoped>
.home-container {
  height: 100%;
}

.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  /* border-bottom: 1px solid #fff; */
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  position: relative;
  width: 100%;
  height: 60px;
}

.header_divStyle {
  display: flex;
  align-items: center;
}

.imgStyle {
  width: 250px;
  height: 48px;
  margin-right: 15px;
  /* width: 50px;
  height: 50px;
  border-radius: 50%;
  margin-right: 15px; */
}

.el-aside {
  background-color: #373d41;
  display: block;
  position: absolute;
  left: 0;
  top: 60px;
  bottom: 0;
}

.el-menu {
  border-right: none;
}

.el-main {
  background-color: #eaedf1;
  position: absolute;
  left: 200px;
  right: 0;
  top: 60px;
  bottom: 0;
  overflow-y: scroll;
}

.iconfont {
  margin-right: 10px;
}

.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
.huanying {
  margin-right: 20px;
  font-size: 16px;
}
.titleStyle {
  position: absolute;
  right: 40%;
  /* bottom: 0; */
  margin-top: 20px;
  color:gray;
}
</style>